package com.goods.controller.business;

import com.goods.business.service.BizCategoryService;
import com.goods.common.model.business.BizProductCategory;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.ProductCategoryTreeNodeVO;
import com.goods.common.vo.business.ProductCategoryVO;
import com.goods.common.vo.system.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RequestMapping("/business/productCategory")
@RestController
public class BizCategoryController {

    @Autowired
    private BizCategoryService bizCategoryService;

    @GetMapping("/categoryTree")
    public ResponseBean<PageVO> getCategoryTree(@RequestParam Map<String,Object> paramMap) {
        PageVO pageVO = bizCategoryService.getCategoryTreeByMap(paramMap);
        return ResponseBean.success(pageVO);
    }

    @GetMapping(value = "/getParentCategoryTree")
    public ResponseBean getParentCategoryTree(){
        List<ProductCategoryTreeNodeVO> bizProductCategories = bizCategoryService.getParentCategoryTree();
        return ResponseBean.success(bizProductCategories);
    }

    @PostMapping("/add")
    public ResponseBean addCategoryProduct(@RequestBody ProductCategoryVO productCategoryVO){
        bizCategoryService.saveBizProductCategory(productCategoryVO);
        return ResponseBean.success();
    }
    @GetMapping("/edit/{id}")
    public ResponseBean editCategoryProduct(@PathVariable Integer id){
//        bizCategoryService.editBizProductCategory(bizProductCategory);
        ProductCategoryTreeNodeVO productCategoryTreeNodeVO = bizCategoryService.getCategoryProById(id);
        return ResponseBean.success(productCategoryTreeNodeVO);
    }

    @PutMapping("/update/{id}")
    public ResponseBean updateCategoryProduct(@PathVariable Integer id, @RequestBody ProductCategoryVO productCategoryVO) {
        bizCategoryService.updateBizProductCategory(id,productCategoryVO);
        return ResponseBean.success();
    }

    @DeleteMapping("/delete/{id}")
    public ResponseBean deleteCategoryProduct(@PathVariable Integer id){
      bizCategoryService.deleteCategoryProductById(id);
        return ResponseBean.success();
    }

}

